<{include file="public/header" /}>
<body>
  
<!-- 顶部搜索 -->
<div class="layui-row">
  <div class="layui-form-item" style="margin: 10px 10px;">
    <button class="layui-btn layui-btn-sm" data-type="reload" id="refresh"><i class="layui-icon layui-icon-refresh"></i>刷新</button>
  </div>
</div>
<!-- 顶部搜索end -->
<table class="layui-hide" id="elist" lay-filter="elist" ></table>
 
<script type="text/html" id="barDemo">
  {{#  var tid = <{$Think.session.uid}>,mark=d.getmarkcount_count;}}
  {{#  if(mark == d.allocate[tid][0]){ }}
    <span style="color: #FF5722;font-size: 15px;">已阅完</span>
  {{#  } else { }}
    <a lay-event="markpaper" style="font-size: 20px; color: #009688; cursor: pointer;"><b>进入阅卷 >></b></a>
  {{#  } }} 
  
  <!-- <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="allocate">阅卷分配</a>
  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a> -->
</script>
<script type="text/html" id="allocateTPL">
    <b style="font-size: 20px;"><span style="color: #FF5722;">{{d.getmarkcount_count}}</span>/<span style="color: #1E9FFF;">{{d.allocate[<{$Think.session.uid}>][0]}}</span></b>
</script>      
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 --> 
 <div style="width: 100%;height: 180px;"></div>
<script>
layui.use(['form','laypage','table','element','laydate','jquery'], function(){
  var table = layui.table,laypage=layui.laypage,element=layui.element,$ = layui.$,form=layui.form;
    $('#refresh').on('click',function(){
    	window.location.reload()
    });
  //数据表格配置
  table.render({
    elem: '#elist'
    ,url:'<{:url('markdata')}>'
    //,toolbar: '#toolbarDemo'
    //,defaultToolbar: ['filter']
    ,title: '阅卷考试列表'
    ,cols: [[
      //{type: 'checkbox', fixed: 'left'}
      {field:'eid', title:'ID', sort: true}
      ,{field:'title', title:'考试',width:'40%'}
      ,{field:'countan',title:'答卷',event:'showstuanswers',style:'cursor: pointer;',templet:function(d){return '<span class="layui-table-link">'+ d.getstuanswers_count +' 份</span>'
      }}
      ,{field:'subject', title:'科目',templet:function(d){return get_question_subject(d.subject)}}
      ,{field:'examstatus', title:'已阅/任务',templet:'#allocateTPL'}
      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:200}
    ]]
    ,page: true
    ,id: 'hereReload'
  });
   
  //监听行工具事件
  table.on('tool(elist)', function(obj){
    var data = obj.data;
    //console.log(obj);
    //alert(data.tid);
    if(obj.event === 'del'){
      layer.confirm('确定删除【'+data.title+'】吗？', function(index){
         $.post("<{:url('del')}>",{id:data.eid},function(data,status){
	          //alert(data);
	          //alert(JSON.stringify(data));
	          //console(data);
	          if(data===1){
	            layer.close(index);
	            obj.del();
	            layer.msg('删除成功！',{time:1000})
	          }else{
	          	layer.close(index);
	            layer.alert(data,{icon:5});
	          }
	     })
      });
    }else if(obj.event === 'markpaper'){
      var data=obj.data;
      //layer.alert(data.eid);
      var nowtime= new Date(),overtime=(data.begintime+data.timelong*60)*1000;
      if (nowtime.getTime()< overtime) {
        layer.alert('考试尚未结束！');
      } else {
        var tid='<{$Think.session.uid}>',starid=data['allocate'][tid][1],marktotal=data['allocate'][tid][0];
        var myendid=starid+ Number(marktotal)-1;
        var str='<{:url("markpaper",["eid"=>"tid","starid"=>"mystarid","endid"=>"myendid"])}>';
        var url=str.replace("tid",data.eid);
        var url1=url.replace("mystarid",starid);
        var url2=url1.replace("myendid",myendid);
        //alert( url2);
        var index=layer.open({
            title:data.title
            ,type: 2 
            ,maxmin: true
            ,area: ['900px', '450px']
            ,content: url2
            // ,success: function (layero, index) {
            //           // 新iframe窗口的对象
            //             var iframeWin = layero.find('iframe')[0].contentWindow;
            //             // 重新渲染checkbox,select同理
            //             iframeWin.layui.form.render();
            //}
        });layer.full(index);
      }
    }else if (obj.event ==='allocate') {
      //window.location.href="<{:url('question/index')}>";
      var data=obj.data;
      //layer.alert(data.eid);
      var str='<{:url("allocate",["id"=>"tid"])}>';
      var url=str.replace("tid",data.eid);
      //alert(url);
      var index=layer.open({
          title:'【阅卷分配】'+data.title
      ,type: 2 
      ,maxmin: true
      ,area: ['500px', '450px']
      ,content: url
      });
    }else if(obj.event === 'showstuanswers'){
      var data=obj.data;
      //layer.alert(JSON.stringify(data));
      var str='<{:url("showstuanswers",["id"=>"tid"])}>';
      var url=str.replace("tid",data.eid);
      //alert(url);
        if (data.getstuanswers_count==0) {
          layer.alert('该考试尚无数据！');
        } else {
          var index1=layer.open({
          title:data.title
          ,type: 2 
          ,maxmin: true
          ,area: ['900px', '450px']
          ,content: url
          });layer.full(index1);
        }
      
    }

  });

  



  //表格重载
	  var active = {
	    reload: function(){
	      var subject = $('#subject');//,grade = $('#grade');
	      
	      //执行重载
	      table.reload('hereReload', {
	        page: {
	          curr: 1 //重新从第 1 页开始
	        }
	        ,where: {
	          //key: {
	            subject: subject.val()//,grade:grade.val()
	          //}
	        }
	      });
	    }
	  };
	  
	  $('#search').on('click', function(){
	    var type = $(this).data('type');
	    active[type] ? active[type].call(this) : '';
	  });
})
</script>
<div style="height: 150px;background-color: white;"></div>
</body>
</html>
